蟻本 2-3 最長共通部分列問題
code: python
n = int(input())
m = int(input())
s = input()
t = input()
dp = [
0
* (n + 1) for i in range(m + 1)]
for i in range(n):
for j in range(m):
if (s
i
== t
j
):
# 左斜め上のマス+1
dp
i + 1
j + 1
= dp
i
j
+ 1
else:
# 左か上のマスで大きい方
dp
i + 1
j + 1
= max(dp
i
j + 1
, dp
i + 1
j
)
print(dp
n
m
)
# 4
# 4
# abcd
# becd
テーマ
#dp